package com.jsyl.lwbk.business.service.impl;

import com.jsyl.lwbk.business.domain.EvaluateRecord;
import com.jsyl.lwbk.business.mapper.education.ChildTrainingProgramMapper;
import com.jsyl.lwbk.business.domain.education.ChildTrainingProgram;
import com.jsyl.lwbk.business.domain.education.ChildTrainingProgramExample;
import com.jsyl.lwbk.business.domain.education.QuestionReporttype;
import com.jsyl.lwbk.business.domain.education.TrainingProgram;
import com.jsyl.lwbk.business.dto.ReportScoreDTO;
import com.jsyl.lwbk.business.dto.education.ChildTrainingProgramDTO;
import com.jsyl.lwbk.business.dto.education.TrainingProgramListDTO;
import com.jsyl.lwbk.business.service.IChildRecordService;
import com.jsyl.lwbk.business.service.IEvaluateReportService;
import com.jsyl.lwbk.business.service.IGenerateProgramService;
import com.jsyl.lwbk.business.service.education.IChildTrainingProgramService;
import com.jsyl.lwbk.business.service.education.IQuestionReporttypeService;
import com.jsyl.lwbk.business.service.education.ITrainingProgramService;
import com.jsyl.lwbk.common.utils.DateUtils;
import com.jsyl.lwbk.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class GenerateProgramServiceImpl implements IGenerateProgramService {

    private static final Logger log = LoggerFactory.getLogger(GenerateProgramServiceImpl.class);

    @Autowired
    private IEvaluateReportService evaluateReportService;

    @Autowired
    private IQuestionReporttypeService questionReporttypeService;

    @Autowired
    private IChildRecordService evalueRecordService;

    @Autowired
    private ITrainingProgramService trainingProgramService;

    @Autowired
    private IChildTrainingProgramService childTrainingProgramService;

    @Autowired
    private ChildTrainingProgramMapper childTrainingProgramMapper;


    private Integer programCount = 2;






    @Override
    @Transactional
    public void generateCurDayChildTraningProgram(String evaluateNumber,Long centerId,Long childId) {
        log.error("立即生成当月训练项目");
        //查看是否已经生成过项目
        ChildTrainingProgramDTO childTrainingProgramDTO = new ChildTrainingProgramDTO();
//        childTrainingProgramDTO.setCenterId(centerId);
        childTrainingProgramDTO.setChildId(childId);
        childTrainingProgramDTO.setTrainingProgramNumber(DateUtils.getDateYYYYMM());
        childTrainingProgramDTO.setTrainingType(3);
        List<ChildTrainingProgram> childTrainingPrograms = childTrainingProgramService.list(childTrainingProgramDTO);
        //查看是否已确认新生标准计划
//        int newProgramCount = this.childTrainingProgramService.countNewProgram(childId,DateUtils.getDateYYYYMM());
        if(CollectionUtils.isEmpty(childTrainingPrograms)) {
            generateByEvaluate(childId, centerId, evaluateNumber);
        }
    }



    private void generateByEvaluate(Long childId,Long centerId,String evaluateNumber){
        List<TrainingProgram> trainingProgramListA = new ArrayList<TrainingProgram>();
        List<TrainingProgram> trainingProgramListB = new ArrayList<TrainingProgram>();
        int replaceCount=0;//构音题目需要替换成言语的个数
        //9大训练报告类型
       for(int i=1;i<=9;i++) {
           Integer questionCount = getQuestionCount(evaluateNumber,i);
           //获取构音的低于“良好”个数，良好时替换成语言类项目
           if(i == 6){
               int noGoodCount= evalueRecordService.getCountByProjectModule(evaluateNumber,5);
               if(noGoodCount<questionCount){
                   replaceCount = questionCount - noGoodCount;
                   questionCount = noGoodCount;
               }
           }
           if(i == 7 && replaceCount>0){
               if(questionCount<2){
                   replaceCount = replaceCount-(2-questionCount);
                   questionCount = questionCount+(2-questionCount);
               }
           }
           if(i == 8 && replaceCount>0){
               questionCount = questionCount+replaceCount;
           }
           if(questionCount == 0){continue;}
           List<Long> questionIds = new ArrayList<Long>();
           //查找训练报告类型对应的题目
           List<QuestionReporttype> questionReporttypes = questionReporttypeService.findListByType((short)i);
           if (CollectionUtils.isEmpty(questionReporttypes)) {
               continue;
           }
           for (QuestionReporttype questionReporttype : questionReporttypes) {
               questionIds.add(questionReporttype.getQuestionId());
           }
           //查出学生该报告类型下题目的测评记录
           List<EvaluateRecord> evaluateRecords = evalueRecordService.findByChildEvaluateNumber(childId, evaluateNumber, questionIds);
           if (CollectionUtils.isEmpty(evaluateRecords)) {
               continue;
           }
           //查询学生已稳定的项目
           ChildTrainingProgramExample childTrainingProgramExample = new ChildTrainingProgramExample();
           childTrainingProgramExample.createCriteria().andChildIdEqualTo(childId).andTrainingLevelEqualTo(0).andQuestionIdIn(questionIds);
           List<ChildTrainingProgram> promotedList = childTrainingProgramMapper.selectByExample(childTrainingProgramExample);


           //从测评记录中随机抽取取得分最高的questionCount道题
           List<EvaluateRecord> selcetList = getEvaluateRecord(evaluateRecords,questionCount*programCount);
           //evaluateRecords剩下的放在selcetList后面，按分值从高到低，防止选中的题目训练项目不够的情况
           evaluateRecords.removeAll(selcetList);
           selcetList.addAll(evaluateRecords);
           //从分值高低顺序选PlanA项目
           //当前题目项目不够取测评记录下一题的项目
           int listSize  = questionCount*programCount;
           List<TrainingProgram> planA = new ArrayList<TrainingProgram>();
           for (int j=0;j<selcetList.size();j++) {
               EvaluateRecord evaluateRecord = selcetList.get(j);
               if(!CollectionUtils.isEmpty(planA) && planA.size()> listSize){
                   planA = planA.subList(0,listSize);
                   trainingProgramListA.addAll(planA);
                   break;
               }
               else if(!CollectionUtils.isEmpty(planA) && planA.size()== listSize){
                   trainingProgramListA.addAll(planA);
                   break;
               }
               List<TrainingProgram> programs = getProgram(childId, evaluateRecord.getQuestionId(), evaluateRecord.getChildScore(), programCount,1,null,i,promotedList);
               //去除抽到重复的项目
               if(!CollectionUtils.isEmpty(planA)){
                   for(TrainingProgram trainingProgram:planA){
                       if(programs.contains(trainingProgram)){
                           programs.remove(trainingProgram);
                       }
                   }
               }
               planA.addAll(programs);
               //最后一题不管怎样都要加到列表，不会再进入下一个循环，多的要删除
               if(j == selcetList.size()-1){
                   if(!CollectionUtils.isEmpty(planA) && planA.size()> listSize){
                       planA = planA.subList(0,listSize);
                   }
                   trainingProgramListA.addAll(planA);
               }
           }
           //选PlanB项目
           List<TrainingProgram> planB = new ArrayList<TrainingProgram>();
           for (int k=0;k<selcetList.size();k++) {
               EvaluateRecord evaluateRecord = selcetList.get(k);
               if(!CollectionUtils.isEmpty(planB) && planB.size()>listSize){
                   planB = planB.subList(0,listSize);
                   trainingProgramListB.addAll(planB);
                   break;
               }
               else if(!CollectionUtils.isEmpty(planB) && planB.size()== listSize){
                   trainingProgramListB.addAll(planB);
                   break;
               }
               List<TrainingProgram> typeBprograms = getProgram(childId, evaluateRecord.getQuestionId(), evaluateRecord.getChildScore(), programCount, 2, trainingProgramListA, i,promotedList);
               //去除抽到重复的项目
               if(!CollectionUtils.isEmpty(planB)){
                   for(TrainingProgram trainingProgram:planB){
                       if(typeBprograms.contains(trainingProgram)){
                           typeBprograms.remove(trainingProgram);
                       }
                   }
               }
               planB.addAll(typeBprograms);
               //最后一题不管怎样都要加到列表，不会再进入下一个循环，多的要删除
               if(k == selcetList.size()-1){
                   if(!CollectionUtils.isEmpty(planB) && planB.size()> listSize){
                       planB = planB.subList(0,listSize);
                   }
                   trainingProgramListB.addAll(planB);
               }
           }
       }
        if (!CollectionUtils.isEmpty(trainingProgramListA)) {
            saveTraninProgram(trainingProgramListA, childId, centerId,evaluateNumber);
        }
        if (!CollectionUtils.isEmpty(trainingProgramListB)) {
            saveTraninProgram(trainingProgramListB, childId, centerId,evaluateNumber);
        }
        //清除新生标准计划
//        this.childTrainingProgramMapper.deleteNewProgram(childId,DateUtils.getDateYYYYMM());
        trainingProgramListA.clear();
        trainingProgramListB.clear();


    }

    //随机抽取题目
    private List<EvaluateRecord> getEvaluateRecord(List<EvaluateRecord> records,int questionCount){
        List<EvaluateRecord> evaluateRecords = new ArrayList<EvaluateRecord>();
        List<EvaluateRecord> records4Score = new ArrayList<EvaluateRecord>();
        List<EvaluateRecord> records3Score = new ArrayList<EvaluateRecord>();
        List<EvaluateRecord> records2Score = new ArrayList<EvaluateRecord>();
        List<EvaluateRecord> records1Score = new ArrayList<EvaluateRecord>();
        List<EvaluateRecord> records0Score = new ArrayList<EvaluateRecord>();
        //测评记录按分值不同存放
        for(EvaluateRecord evaluateRecord:records){
            if(evaluateRecord.getChildScore() == null){
                continue;
            }
            //已稳定数目
            int stableCount = this.childTrainingProgramMapper.selectStableCount(evaluateRecord.getChildId(),evaluateRecord.getQuestionId());
            //对应题目、分数下的总题目数
            int totalCount = this.trainingProgramService.subjectCount(evaluateRecord.getQuestionId(),evaluateRecord.getChildScore());
            if((double)stableCount/totalCount>0.7){
                evaluateRecord.setChildScore(evaluateRecord.getChildScore()>0?(evaluateRecord.getChildScore()-1):0);
            }
            if(evaluateRecord.getChildScore() ==4){
                records4Score.add(evaluateRecord);
            }
            else if(evaluateRecord.getChildScore() ==3){
                records3Score.add(evaluateRecord);
            }
            else if(evaluateRecord.getChildScore() ==2){
                records2Score.add(evaluateRecord);
            }
            else if(evaluateRecord.getChildScore() ==1){
                records1Score.add(evaluateRecord);
            }
            else if(evaluateRecord.getChildScore() ==0){
                records0Score.add(evaluateRecord);
            }
        }

        if (questionCount < records4Score.size()) {
            Collections.shuffle(records4Score);
            for (int i = 0; i < questionCount; i++) {
//                int r = getRandom(records4Score.size());
                evaluateRecords.add(records4Score.get(i));
            }
            return evaluateRecords;
        } else if (questionCount == records4Score.size()) {
            evaluateRecords.addAll(records4Score);
            return evaluateRecords;
        } else if (questionCount > records4Score.size()) {
            evaluateRecords.addAll(records4Score);
            //还剩几题
            int s3 = questionCount - records4Score.size();
            if (s3 < records3Score.size()) {
                Collections.shuffle(records3Score);
                for (int i = 0; i < s3; i++) {
//                    int r = getRandom(s3);
                    evaluateRecords.add(records3Score.get(i));
                }
                return evaluateRecords;
            } else if (s3 == records3Score.size()) {
                evaluateRecords.addAll(records3Score);
                return evaluateRecords;
            } else if (s3 > records3Score.size()) {
                evaluateRecords.addAll(records3Score);
                //还剩几题
                int s2 = (questionCount - records4Score.size()) - records3Score.size();
                if (s2 < records2Score.size()) {
                    Collections.shuffle(records2Score);
                    for (int i = 0; i < s2; i++) {
//                        int r = getRandom(s2);
                        evaluateRecords.add(records2Score.get(i));
                    }
                    return evaluateRecords;
                } else if (s2 == records2Score.size()) {
                    evaluateRecords.addAll(records2Score);
                    return evaluateRecords;
                } else if (s2 > records2Score.size()) {
                    evaluateRecords.addAll(records2Score);
                    //还剩几题
                    int s1 = ((questionCount - records4Score.size()) - records3Score.size()) - records2Score.size();
                    if (s1 < records1Score.size()) {
                        Collections.shuffle(records1Score);
                        for (int i = 0; i < s1; i++) {
//                            int r = getRandom(s1);
                            evaluateRecords.add(records1Score.get(i));
                        }
                        return evaluateRecords;
                    } else if (s1 == records1Score.size()) {
                        evaluateRecords.addAll(records1Score);
                        return evaluateRecords;
                    } else if (s1 > records1Score.size()) {
                        evaluateRecords.addAll(records1Score);
                        //还剩几题
                        int s0 = (((questionCount - records4Score.size()) - records3Score.size()) - records2Score.size()) - records1Score.size();
                        if (s0 < records0Score.size()) {
                            Collections.shuffle(records0Score);
                            for (int i = 0; i < s0; i++) {
//                                int r = getRandom(s0);
                                evaluateRecords.add(records0Score.get(i));
                            }
                            return evaluateRecords;
                        } else if (s1 == records0Score.size()) {
                            evaluateRecords.addAll(records0Score);
                            return evaluateRecords;
                        }
                    }
                }
            }

        }

        return evaluateRecords;
    }


    //n=10,则随机抽取0-9
    private int getRandom(int n){
       return  (int)(Math.random()*n);
    }





    private void dealList(List<TrainingProgram> trainingProgramList,Long questionId,Integer typeAB,Integer trainingModule){
        if(!CollectionUtils.isEmpty(trainingProgramList)) {
            for (TrainingProgram trainingProgram : trainingProgramList) {
                trainingProgram.setTypeAB(typeAB);
                //设置回原来的题目ID
                //多个题目共用训练项目的情况
                trainingProgram.setQuestionId(questionId);
                trainingProgram.setTrainingModule(trainingModule);
            }
        }
    }

    //挑选训练项目PlanB
    private List<TrainingProgram> getPlanB(Long childId,Long questionId,Integer score,Integer programCount,Integer typeAB,List<TrainingProgram> planA,Integer trainingModule,List<ChildTrainingProgram> promotedList){
        List<TrainingProgram> trainingProgramList = new ArrayList<TrainingProgram>();
//        ChildTrainingProgramExample childTrainingProgramExample = new ChildTrainingProgramExample();
//        childTrainingProgramExample.createCriteria().andChildIdEqualTo(childId).andTrainingLevelEqualTo(1).andQuestionIdEqualTo(questionId).andTrainingScoreEqualTo(score);
//        List<ChildTrainingProgram> promotedList = childTrainingProgramMapper.selectByExample(childTrainingProgramExample);

        TrainingProgramListDTO trainingProgramListDTO = new TrainingProgramListDTO();
        //多个题目共用训练项目的情况
        trainingProgramListDTO.setQuestionId(getQuestionId(questionId));
        trainingProgramListDTO.setTrainingScore(score);
        List<TrainingProgram> programs = trainingProgramService.findList(trainingProgramListDTO);

        trainingProgramList.addAll(getProgram(childId,questionId,score,programCount,typeAB,planA,trainingModule,promotedList));
//        Integer promoted = isPromoted(promotedList,programs);
//        if(promoted == 0){
//            trainingProgramList.addAll(getProgram(childId,questionId,score,programCount,typeAB,planA,trainingModule));
//        }
//        else if(promoted ==1){
//            trainingProgramList.addAll(getProgram(childId,questionId,score,programCount-1,typeAB,planA,trainingModule));
//            trainingProgramList.addAll(getProgram(childId,questionId,score-1,1,typeAB,planA,trainingModule));
//        }

        return trainingProgramList;
    }


    private List<TrainingProgram> getProgram(Long childId,Long questionId,Integer score,Integer programCount,Integer typeAB,List<TrainingProgram> planA,Integer trainingModule,List<ChildTrainingProgram> promotedList){
        List<TrainingProgram> trainingProgramList = new ArrayList<TrainingProgram>();
        Integer curScore = score;
//        while (curScore >=0){
//            ChildTrainingProgramExample childTrainingProgramExample = new ChildTrainingProgramExample();
//            childTrainingProgramExample.createCriteria().andChildIdEqualTo(childId).andTrainingLevelEqualTo(1).andQuestionIdEqualTo(questionId).andTrainingScoreEqualTo(score);
//            List<ChildTrainingProgram> promotedList = childTrainingProgramMapper.selectByExample(childTrainingProgramExample);

            TrainingProgramListDTO trainingProgramListDTO = new TrainingProgramListDTO();
            //多个题目共用训练项目的情况
            trainingProgramListDTO.setQuestionId(getQuestionId(questionId));
            trainingProgramListDTO.setTrainingScore(curScore);
            List<TrainingProgram> programs = trainingProgramService.findList(trainingProgramListDTO);
            Collections.shuffle(programs);
//            Integer promoted = isPromoted(promotedList,programs);
            //0.programs就是要查的列表 1.programs是其中原分值的列表，再加上分值减1的列表 2.programs清空需加上分值减1的列表
//            if(promoted ==1){
//                programs.addAll(getProgram(childId,questionId,score-1,1,typeAB,planA,trainingModule));
//            }
//            else if(promoted ==2){
//                programs.clear();
//                programs.addAll(getProgram(childId,questionId,score-1,programCount,typeAB,planA,trainingModule));
//            }

            if(!CollectionUtils.isEmpty(programs)){
                //去除planA的项目
                if(!CollectionUtils.isEmpty(planA)) {
                    programs.removeAll(planA);
                }
                if(!CollectionUtils.isEmpty(programs)) {
                    //去除已稳定的项目
                    if(!CollectionUtils.isEmpty(promotedList)) {
                        List<TrainingProgram> temPrograms = new ArrayList<TrainingProgram>();
                        temPrograms.addAll(programs);
                        for (TrainingProgram trainingProgram : temPrograms) {
                            for (ChildTrainingProgram childTrainingProgram : promotedList) {
                                if (trainingProgram.getId() != null && childTrainingProgram.getTrainingProgramId() != null) {
                                    if (trainingProgram.getId().equals(childTrainingProgram.getTrainingProgramId())) {
                                        programs.remove(trainingProgram);
                                    }
                                }
                            }
                        }
                    }
                }
                //去除抽到重复的项目
                if(!CollectionUtils.isEmpty(trainingProgramList)){
                    for(TrainingProgram trainingProgram:trainingProgramList){
                        if(programs.contains(trainingProgram)){
                            programs.remove(trainingProgram);
                        }
                    }
                }
                trainingProgramList.addAll(programs);
            }
            if(trainingProgramList.size()>= programCount){
                if (trainingProgramList.size() > programCount) {
                    List<TrainingProgram> curList = trainingProgramList.subList(0, programCount);
                    dealList(curList,questionId,typeAB,trainingModule);
                    return curList;
                }
                dealList(trainingProgramList,questionId,typeAB,trainingModule);
                return trainingProgramList;
            }
//            else {
//                curScore--;
//            }
//        }
        dealList(trainingProgramList,questionId,typeAB,trainingModule);
        return trainingProgramList;
    }

    //判断该题目该分值是否已经晋级
    private Integer isPromoted(List<ChildTrainingProgram> promotedList,List<TrainingProgram> programs){
        if(CollectionUtils.isEmpty(promotedList)){
            return 0;
        }
        if(CollectionUtils.isEmpty(programs)){
            return 0;
        }
        DecimalFormat df=new DecimalFormat("0.00");
        String data = df.format((double) promotedList.size() / programs.size());
        if(StringUtils.isEmpty(data)){
            return 0;
        }
        Double rate = Double.parseDouble(data);
        if(rate < 0.4){
            return 0;
        }
        else if(rate>=0.4 && rate<=0.69){
            return 1;
        }
        else if(rate>=0.7){
            return 2;
        }
        return 0;
    }

    //多个题目共用一套项目的情况
    private Long getQuestionId(Long questionId){
        Long returnId = questionId;
        if(questionId == 5){
            returnId = 4L;
        }
        else if(questionId == 9){
            returnId = 8L;
        }
        else if(questionId == 12){
            returnId = 11L;
        }
        else if(questionId == 14){
            returnId = 13L;
        }
        else if(questionId == 16){
            returnId = 15L;
        }
        else if(questionId == 18){
            returnId = 17L;
        }
        else if(questionId == 20){
            returnId = 19L;
        }
        return returnId;
    }



    private void saveTraninProgram(List<TrainingProgram> trainingPrograms,Long childId,Long centerId,String evaluateNumber){
        for (int i = 0; i < trainingPrograms.size(); i++) {
            insert(trainingPrograms.get(i), childId, centerId, i,evaluateNumber);
        }
    }

    private void insert(TrainingProgram trainingProgram,Long childId,Long centerId,Integer num,String evaluateNumber){
        ChildTrainingProgram childTrainingProgram = new ChildTrainingProgram();
        childTrainingProgram.setCenterId(centerId);
        childTrainingProgram.setChildId(childId);
        childTrainingProgram.setTrainingProgramNumber(DateUtils.getDateYYYYMM());
        childTrainingProgram.setProjectType(trainingProgram.getProjectType());
        childTrainingProgram.setInputType(trainingProgram.getInputType());
        childTrainingProgram.setProjectModule(trainingProgram.getProjectModule());
        childTrainingProgram.setQuestionId(trainingProgram.getQuestionId());
        childTrainingProgram.setTrainingScore(trainingProgram.getTrainingScore());
        childTrainingProgram.setTrainingModule(trainingProgram.getTrainingModule());
        childTrainingProgram.setTrainingProgramId(trainingProgram.getId());
        childTrainingProgram.setTrainingPlan(trainingProgram.getTypeAB());
        childTrainingProgram.setTrainingType(1);
        childTrainingProgram.setTrainingNum((num+1)+"");
        childTrainingProgram.setTempGenerateDay(DateUtils.getDate());
        childTrainingProgram.setStatus(0);
        //判断该小孩该项目是否已稳定
        ChildTrainingProgramExample childTrainingProgramExample = new ChildTrainingProgramExample();
        childTrainingProgramExample.createCriteria().andChildIdEqualTo(childId).andTrainingLevelEqualTo(1).andTrainingProgramIdEqualTo(trainingProgram.getId());
        List<ChildTrainingProgram> promotedList = childTrainingProgramMapper.selectByExample(childTrainingProgramExample);
        if(!CollectionUtils.isEmpty(promotedList)) {
            childTrainingProgram.setTrainingLevel(1);
        }

        childTrainingProgram.setTrainingName(trainingProgram.getTrainingName());
        childTrainingProgram.setTrainingContent(trainingProgram.getTrainingContent());
        childTrainingProgram.setModifyDirection(trainingProgram.getModifyDirection());
        childTrainingProgram.setModifyContent(trainingProgram.getModifyContent());
        childTrainingProgram.setCreateTime(new Date());
        childTrainingProgram.setEvaluateNumber(evaluateNumber);
        childTrainingProgramService.insert(childTrainingProgram);
    }

    //言语级别
    private Short getLanGrade(String evaluateNumber){
        List<ReportScoreDTO> reportScoreDTOS = evaluateReportService.listProjectModuleScore(evaluateNumber);
        if(CollectionUtils.isEmpty(reportScoreDTOS)){
            return 0;
        }
        Double gradeScore =  0d;
        DecimalFormat df=new DecimalFormat("0.00");
        for(ReportScoreDTO reportScoreDTO:reportScoreDTOS){
            double weigh = 0d;
            if(reportScoreDTO.getProjectModule() == 1){
                weigh = 0.055;
            }
            else if(reportScoreDTO.getProjectModule() == 2){
                weigh = 0.105;
            }
            else if(reportScoreDTO.getProjectModule() == 3){
                weigh = 0.12;
            }
            else if(reportScoreDTO.getProjectModule() == 4){
                weigh = 0.17;
            }
            else if(reportScoreDTO.getProjectModule() == 5){
                weigh = 0.055;
            }
            else if(reportScoreDTO.getProjectModule() == 6){
                weigh = 0.25;
            }
            else if(reportScoreDTO.getProjectModule() == 7){
                weigh = 0.125;
            }
            else if(reportScoreDTO.getProjectModule() == 8){
                weigh = 0.12;
            }
            if(reportScoreDTO.getScore()!= null && reportScoreDTO.getTotalScore()!=null) {
                String data = df.format((double) reportScoreDTO.getScore() / reportScoreDTO.getTotalScore());
                gradeScore = gradeScore + (Double.parseDouble(data)* 100 * weigh);
            }
        }
        if(gradeScore>59 && gradeScore<=100){
            return 0;
        }
        else if(gradeScore>39 && gradeScore<=59){
            return 1;
        }
        else if(gradeScore>=0 && gradeScore<=39){
            return 2;
        }
        return 0;
    }


    private Integer getQuestionCount(String evaluateNumber, Integer i){
        Integer questionCount = 0;
        if(i==1){
            questionCount = 3;
            return questionCount;
        }
        else if(i==2){
            questionCount = 2;
            return questionCount;
        }
        else if(i==3){
            questionCount = 1;
            return questionCount;
        }
        else if(i==4){
            questionCount = 4;
            return questionCount;
        }
        else if(i==5){
            questionCount = 2;
            return questionCount;
        }
        Short grade = getLanGrade(evaluateNumber);
        if(grade == 0){
            if(i==6){
                questionCount =3;
            }
            else if(i==7){
                questionCount =0;
            }
            else if(i==8){
                questionCount =1;
            }
            else if(i==9){
                questionCount =2;
            }
        }
        else if(grade == 1){
            if(i==6){
                questionCount =0;
            }
            else if(i==7){
                questionCount =2;
            }
            else if(i==8){
                questionCount =2;
            }
            else if(i==9){
                questionCount =2;
            }
        }
        else if(grade == 2){
            if(i==6){
                questionCount =1;
            }
            else if(i==7){
                questionCount =1;
            }
            else if(i==8){
                questionCount =2;
            }
            else if(i==9){
                questionCount =2;
            }
        }

        return questionCount;
    }

}
